
#ifndef _TTG_EXTRAS_SERIALIZATION_SERIALIZER_
#define _TTG_EXTRAS_SERIALIZATION_SERIALIZER_
#include "Common/Definitions.h"

#include <string.h>
#include <string>
#include "Common/Structures.h"
#include "DeSerializer.h"

namespace ttg
{
	namespace extras
	{
		namespace serialization
		{
			//Base class for any serializer.
			class Serializer
			{
				protected:
					//Serializes given part of memory.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					//Note: in case of error should throw ttg::Error().
					virtual void serializeMemory(const void *data, size_t size, const char *name) = 0;
					//Serializes information about start of new reference (xml analogue is section tag).
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					//Note: in case of error should throw ttg::Error().
					virtual void serializeReferenceStart(bool is_null, const char *name) = 0;
					//Serializes information about end of reference (xml analogue is section tag).
					//Note: in case of error should throw ttg::Error().
					virtual void serializeReferenceEnd() = 0;
				public:
					//Creates correct deserialized for serialized data.
					//Note: returned object shoul be deleted explicitly.
					virtual DeSerializer *createDeSerializer() = 0;
					//Serializes given int value.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					inline void serializeInt(__int32 value, const char *name)
					{ serializeMemory(&value, sizeof(__int32), name); }
					//Serializes given bool value.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					inline void serializeBool(bool value, const char *name)
					{ serializeMemory(&value, sizeof(bool), name); }
					//Serializes given float value.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					inline void serializeFloat(float value, const char *name)
					{ serializeMemory(&value, sizeof(float), name); }
					//Serializes given double value.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					inline void serializeDouble(double value, const char *name)
					{ serializeMemory(&value, sizeof(double), name); }
					//Serializes given std::string value.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					inline void serializeString(const std::string &value, const char *name)
					{ serializeString(value.c_str(), name); }
					//Serializes given const char * value.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					void serializeString(const char *value, const char *name);
					//Serializes given object.
					//Note: "name" should be equal to variable name and will be used for
					//deserialization success checking.
					void serializeObject(structures::SerializableObject *object, const char *name);
			};
		}
	}
}

#endif
